import Qt 4.7

Rectangle {
    id: box

    width: 81; height: 52
    color: defaultColor
    radius: 5
    border.width: 0

    property bool noBox: false
    property bool toggleEnable: false
    property bool isToggled: false

    property alias text: buttonText.text

    property string textColor: "white"
    property string textColorToggled: "white"

    property int fontPointSize: 7

    property color pressedColor: Qt.darker("darkGray")
    property color toggledColor: "black"
    property color defaultColor: "#00adef"

    signal clicked
    signal toggled

    function toggle() {
        if (box.isToggled == true) {
            box.isToggled = false
            box.color = box.defaultColor
            buttonText.color = box.textColor
        } else {
            box.isToggled = true
            box.color = box.toggledColor
            buttonText.color = box.textColorToggled
        }
        box.toggled()
    }

    function turnOff() {
        box.isToggled = false;
        box.color = box.defaultColor;
        buttonText.color = box.textColor;
    }

    Text {
        id: buttonText

        color: box.textColor
        text: ""
        font { pointSize: parent.fontPointSize; family: "Series 60 Sans"; weight: Font.DemiBold }
        horizontalAlignment: Text.AlignHCenter; verticalAlignment: Text.AlignVCenter
        anchors.fill: parent
    }

    MouseArea {
        id: mouseArea

        anchors.fill: parent

        onClicked: {
            if (parent.toggleEnable == true ) {
                parent.toggle()
            }
            parent.clicked()
        }

        onPressed: {
            if (noBox == false)
                box.color = box.pressedColor
        }

        onReleased: {
            if (noBox == false)
               box.color = box.defaultColor
        }
    }
}
